package com.lagou;

import com.lagou.bean.ByeComponent;
import com.lagou.bean.ComsumerComponet;
import com.lagou.bean.MonitorComponent;
import com.lagou.service.MonitorService;
import org.apache.dubbo.config.spring.context.annotation.EnableDubbo;
import org.apache.dubbo.rpc.RpcContext;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.PropertySource;

public class AnnotationConsumerMain  {
    public static void main(String[] args) throws  Exception {
        System.out.println("-------------");
        AnnotationConfigApplicationContext   context = new AnnotationConfigApplicationContext(ConsumerConfiguration.class);
        context.start();
        // 获取消费者组件
        ComsumerComponet  service = context.getBean(ComsumerComponet.class);
        ByeComponent byeService = context.getBean(ByeComponent.class);
//        MonitorComponent monitorService = context.getBean(MonitorComponent.class);
        while(true){
             System.in.read();
             RpcContext.getContext().setAttachment("clientIp", "192.168.1.110");
             String  hello = service.sayHello("world");
             System.out.println("result:"+hello);

             String bye = byeService.sayBye("Rrrr");
             System.out.println(">>>Bye:" + bye);
//             byeService.methodA();
//             byeService.methodB();
//             byeService.methodC();

            /*** @todo  *****/
//            monitorService.methodA();
//            monitorService.methodB();
//            monitorService.methodC();
        }
    }
    @Configuration
    @PropertySource("classpath:/dubbo-consumer.properties")
    @ComponentScan(basePackages = "com.lagou.bean")
    @EnableDubbo
    static  class  ConsumerConfiguration{

    }
}
